﻿using System;
using System.IO;
using System.Net.Mail;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Xml.Linq;
using TireService.EmailNotification;
using System.Web.Security;
using System.Configuration;

namespace TireService.Data
{
    /// <summary>
    /// Summary description for EmailNotificationServices
    /// </summary>
    public class EmailNotificationServices
    {
        #region Temp email for tirequotation (2013-03-03)


        public void SendTireQuotation(string CustomerEmail, int CustomerId, string CustomerName, string RegistrationNumber, string Note, string HF, string VF, string HB, string VB, string AcceptLink, string RejectLink, string TireDescription, string Qty, string TirePriceExVat, string TirePriceTotalExVat, string EnvPriceTotalExVat, string MontPriceExVat, string MontPriceTotalExVat, string TotalExVat, string TotalVat, string Total)
        {
            string Subject = "Mobilhjulskift.dk - Tilbud på udskiftning af dæk";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(Membership.GetUser().ProviderUserKey.ToString()); // System ID - Jannik79

            // Send email to customer
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendTireQuotation(CustomerName, RegistrationNumber, Note, HF, VF, HB, VB, AcceptLink, RejectLink, TireDescription, Qty, TirePriceExVat, TirePriceTotalExVat, EnvPriceTotalExVat, MontPriceExVat, MontPriceTotalExVat, TotalExVat, TotalVat, Total), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), SystemUserId);
        }

        public void SendTireQuotationAcceptance(string CustomerEmail, int CustomerId, string CustomerName, string RegistrationNumber, string TireDescription, string Qty, string TirePriceExVat, string TirePriceTotalExVat, string EnvPriceTotalExVat, string MontPriceExVat, string MontPriceTotalExVat, string TotalExVat, string TotalVat, string Total)
        {
            string Subject = "Bekræftelse på accept af tilbud";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(Membership.GetUser("Jannik79").ProviderUserKey.ToString()); // System ID - Jannik79
            
            // Send email to customer with user on bcc
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendTireQuotationAccept(CustomerName, RegistrationNumber, TireDescription, Qty, TirePriceExVat, TirePriceTotalExVat, EnvPriceTotalExVat, MontPriceExVat, MontPriceTotalExVat, TotalExVat, TotalVat, Total), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), SystemUserId);
        }

        public void SendTireQuotationRejection(string CustomerEmail, int CustomerId, string CustomerName, string RegistrationNumber, string TireDescription, string Qty, string TirePriceExVat, string TirePriceTotalExVat, string EnvPriceTotalExVat, string MontPriceExVat, string MontPriceTotalExVat, string TotalExVat, string TotalVat, string Total)
        {
            string Subject = "Afvisning af dæk tilbud";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(Membership.GetUser("Jannik79").ProviderUserKey.ToString()); // System ID - Jannik79

            // Send email to customer with user on bcc
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendTireQuotationReject(CustomerName, RegistrationNumber, TireDescription, Qty, TirePriceExVat, TirePriceTotalExVat, EnvPriceTotalExVat, MontPriceExVat, MontPriceTotalExVat, TotalExVat, TotalVat, Total), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), SystemUserId);
        }

        #endregion


        #region Email Generated by Customer or Interface Actions

        /// <summary>
        /// Function that sends email to customer with userlogin to website
        /// </summary>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <param name="CustomerId"></param>
        public void Customer_UserInformation_SendCustomerEmail(string CustomerEmail, string CustomerName, string UserName, string Password, int CustomerId)
        {
            string Subject = "Brugerlogin til mobilhjulskift.dk";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(ConfigurationSettings.AppSettings["SystemUserId"].ToString()); // System ID - Jannik79

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendEmailUserInfoStandard(CustomerName, UserName, Password), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), SystemUserId);
        }

        /// <summary>
        /// Function that sends email to customer with order confirmation invoice attached
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="InvoiceId"></param>
        /// <param name="attachment"></param>
        /// <param name="FileName"></param>
        /// <param name="PaymentAction"></param>
        /// <param name="PaymentLink"></param>
        /// <param name="BookingLink"></param>
        public void Customer_OrderConfirmationAndInvoice_SendCustomerEmail(int CustomerId, string CustomerEmail, string CustomerName, string InvoiceId, byte[] attachment, string FileName, string PaymentAction, string PaymentLink, string BookingLink)
        {
            string Subject = "Ordre bekræftelse - Mobilhjulskift.dk";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(ConfigurationSettings.AppSettings["SystemUserId"].ToString()); // System ID - Jannik79

            MemoryStream attach = new MemoryStream();
            attach.Write(attachment, 0, attachment.Length);
            attach.Position = 0;

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendCustomerSubscriptionOrderConfirmation(CustomerName, PaymentLink, CustomerId.ToString(), InvoiceId, PaymentAction, BookingLink), Subject, true, test, null, attach, FileName, Convert.ToInt32(CustomerId), SystemUserId);
        }

        /// <summary>
        /// Function that sends email to customer with invoice and link to online payment (can be used for sending and resending all types of invoices)
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="InvoiceId"></param>
        /// <param name="attachment"></param>
        /// <param name="FileName"></param>
        /// <param name="PaymentAction"></param>
        /// <param name="PaymentLink"></param>
        public void Customer_Invoice_SendCustomerEmail(int CustomerId, string CustomerEmail, string CustomerName, string InvoiceId, byte[] attachment, string FileName, string PaymentAction, string PaymentLink)
        {
            string Subject = "Mobilhjulskift.dk - Faktura " + InvoiceId;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(ConfigurationSettings.AppSettings["SystemUserId"].ToString()); // System ID - Jannik79

            MemoryStream attach = new MemoryStream();
            attach.Write(attachment, 0, attachment.Length);
            attach.Position = 0;

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendCustomerInvoice(CustomerName, PaymentLink, CustomerId.ToString(), InvoiceId, PaymentAction), Subject, true, test, null, attach, FileName, Convert.ToInt32(CustomerId), SystemUserId);
        }

        /// <summary>
        /// Function that sends email to customer with reminder on invoice and link to online payment (can be used for sending and resending all types of invoices)
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="InvoiceId"></param>
        /// <param name="attachment"></param>
        /// <param name="FileName"></param>
        /// <param name="PaymentAction"></param>
        /// <param name="PaymentLink"></param>
        public void Customer_InvoiceReminder_SendCustomerEmail(int CustomerId, string CustomerEmail, string CustomerName, string InvoiceId, byte[] attachment, string FileName, string PaymentAction, string PaymentLink)
        {
            string Subject = "Mobilhjulskift.dk - Betalingspåmindelse Faktura " + InvoiceId;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(ConfigurationSettings.AppSettings["SystemUserId"].ToString()); // System ID - Jannik79

            MemoryStream attach = new MemoryStream();
            attach.Write(attachment, 0, attachment.Length);
            attach.Position = 0;

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendCustomerInvoiceReminder(CustomerName, PaymentLink, CustomerId.ToString(), InvoiceId, PaymentAction), Subject, true, test, null, attach, FileName, Convert.ToInt32(CustomerId), SystemUserId);
        }

        /// <summary>
        /// Function that sends email to customer with confirmation on the booking they have made themselfs
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="CustomerName"></param>
        /// <param name="ScheduleDate"></param>
        /// <param name="TimeSpan"></param>
        /// <param name="Address"></param>
        /// <param name="ZipCode"></param>
        /// <param name="City"></param>
        /// <param name="ServiceComments"></param>
        public void Customer_ServiceDriveBookingConfirmation_SendCustomerEmail(int CustomerId, string CustomerEmail, string RegistrationNumber, string CustomerName, string ScheduleDate, string TimeSpan, string Address, string ZipCode, string City, string ServiceComments) 
        {
            string Subject = "Bekræftelse af hjulskifts booking til " + RegistrationNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(ConfigurationSettings.AppSettings["SystemUserId"].ToString()); // System ID - Jannik79

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendConfirmationOnSelfServiceBookingSchedule(CustomerName, ScheduleDate, TimeSpan, Address, ZipCode, City, ServiceComments), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), SystemUserId);
        }

        /// <summary>
        /// Function that sends email to customer with reminder on confirmed booking
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="CustomerName"></param>
        /// <param name="ScheduleDate"></param>
        /// <param name="TimeSpan"></param>
        /// <param name="Address"></param>
        /// <param name="ZipCode"></param>
        /// <param name="City"></param>
        /// <param name="ServiceComments"></param>
        public void Customer_ServiceDriveBookingReminder_SendCustomerEmail(int CustomerId, string CustomerEmail, string RegistrationNumber, string CustomerName, string ScheduleDate, string TimeSpan, string Address, string ZipCode, string City, string ServiceComments)
        {
            string Subject = "Husk din hjulskift booking til " + RegistrationNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(ConfigurationSettings.AppSettings["SystemUserId"].ToString()); // System ID - Jannik79

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendReminderBookingSchedule(CustomerName, ScheduleDate, TimeSpan, Address, ZipCode, City, ServiceComments), Subject, true, test, "jannik79@gmail.com", null, null, Convert.ToInt32(CustomerId), SystemUserId);
        }

        /// <summary>
        /// Function that sends email to customer with bookinglink
        /// </summary>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="CustomerId"></param>
        /// <param name="BookingLink"></param>
        public void Customer_RequestBookingLink_SendCustomerEmail(string CustomerEmail, string CustomerName, int CustomerId, string BookingLink)
        {
            Guid SystemUserId = new Guid(ConfigurationSettings.AppSettings["SystemUserId"].ToString()); // System ID - Jannik79

            MembershipUser user = Membership.GetUser((object)SystemUserId);

            CustomerBookingLink_SendCustomerEmail(CustomerEmail, CustomerName, CustomerId, user, BookingLink);
        }

        /// <summary>
        /// Function that sends email to potential new customer on behalf of an existing customer with voucher code
        /// </summary>
        /// <param name="PotentialCustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="CustomerMessage"></param>
        /// <param name="Voucher"></param>
        public void Customer_Voucher_SendEmail(string PotentialCustomerEmail, string CustomerName, string CustomerMessage, string Voucher)
        {
            string Subject = CustomerName + " har sendt dig en rabatkode til Mobilhjulskift.dk";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            // Send email to customer - no bcc email
            email.SendEmail(PotentialCustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendResellerQuotationCode(CustomerName, CustomerMessage, Voucher), Subject, true, test, null, null, null);
        }

        /// <summary>
        /// Function that sends email to customer to finalise signup (used in Interfaces where customer is created, but not subscription and car)
        /// </summary>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="CustomerId"></param>
        public void Interface_FinaliseSignUp_SendCustomerEmail(string CustomerEmail, string CustomerName, int CustomerId)
        {
            string Subject = "Oprettelse hos mobilhjulskift.dk";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(ConfigurationSettings.AppSettings["SystemUserId"].ToString()); // System ID - Jannik79

            string FinaliseLink = ConfigurationSettings.AppSettings["Website"].ToString() + "Integration\\Opret.aspx?cid=" + CustomerId.ToString(); 

            // Send email to customer
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendFinaliseSignUpLink(CustomerName, FinaliseLink), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), SystemUserId);
        }

        #endregion


        #region SystemEmails - require user logged in

        /// <summary>
        /// Function that sends email to customer with information on completed service
        /// </summary>
        /// <param name="CustomerId">Customer Id for logging purposes</param>
        /// <param name="CustomerEmail">Customer email that this email will be send to</param>
        /// <param name="CustomerName">Name on customer</param>
        /// <param name="SubscriptionNumber">SubscriptionNumber for customer</param>
        /// <param name="ScheduleDate">Date service was done</param>
        /// <param name="ServiceDone">List of services done for the customer</param>
        /// <param name="CustomerFeedbackURL">URL to website so customer can provide feedback</param>
        public void ServiceDriveCompleted_SendCustomerEmail(int CustomerId, string CustomerEmail, string CustomerName, string SubscriptionNumber, string ScheduleDate, string ServiceDone, bool AskForReview, string CustomerFeedbackURL)
        {
            string Subject = "Service gennemført - Abonnement " + SubscriptionNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));
            Shared email = new Shared();

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            MembershipUser user = Membership.GetUser();

            if (AskForReview)
            {
                email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendServiceCompletionCustomerNotificationPlusReview(CustomerName, ServiceDone, ScheduleDate, CustomerFeedbackURL), Subject, true, test, user.Email, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
            }
            else
            {
                email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendServiceCompletionCustomerNotification(CustomerName, ServiceDone, ScheduleDate), Subject, true, test, user.Email, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
            }

            
        }

        /// <summary>
        /// Function that sends email to customer with information on tireset pattterns
        /// </summary>
        /// <param name="CustomerId">Customer Id for logging purposes</param>
        /// <param name="CustomerEmail">Customer email that this email will be send to</param>
        /// <param name="CustomerName">Name on customer</param>
        /// <param name="RegistrationNumber">Registration number on car</param>
        /// <param name="tireset">Tireset object</param>
        /// <param name="db">Connection to database</param>
        public void TireSetPattern_SendCustomerEmail(int CustomerId, string CustomerEmail, string CustomerName, string RegistrationNumber, TireSet tireset, TireServiceDB db)
        {
            // Send email to customer
            string Subject = "Dækmønster på " + RegistrationNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            MembershipUser user = Membership.GetUser();

            Shared email = new Shared();

            // Send email to customer with tire set pattern witth us on bcc
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendTireSetPattern(CustomerName, db.GetTireTypeDescription(tireset.TireTypeId), RegistrationNumber, tireset.RightFrontTirePattern.ToString(), tireset.LeftFrontTirePattern.ToString(), tireset.RightRearTirePattern.ToString(), tireset.LeftRearTirePattern.ToString()), Subject, true, test, user.Email, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer with service drive booking suggestion
        /// </summary>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="TireSetType"></param>
        /// <param name="ScheduleDate"></param>
        /// <param name="TimeSpan"></param>
        /// <param name="Address"></param>
        /// <param name="ZipCode"></param>
        /// <param name="City"></param>
        /// <param name="CustomerId"></param>
        /// <param name="SubscriptionId"></param>
        /// <param name="CustomerSubscriptionId"></param>
        /// <param name="CustomerApprovalLink"></param>
        /// <param name="CustomerDisapprovalLink"></param>
        public void BookServiceDrive_SendCustomerEmail(string CustomerEmail, string CustomerName, string RegistrationNumber, string TireSetType, string ScheduleDate, string TimeSpan, string Address, string ZipCode, string City, string CustomerId, string SubscriptionId, string CustomerSubscriptionId, string CustomerApprovalLink, string CustomerDisapprovalLink)
        {
            string Subject = "Booking af tid til hjulskift (Abonnement " + CustomerId + "-" + SubscriptionId + "-" + CustomerSubscriptionId + ")";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            // Send email to customer with service drive booking with user on bcc
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendServiceCarScheduleDetailBooking(CustomerName, RegistrationNumber, TireSetType, ScheduleDate, TimeSpan, Address, ZipCode, City, CustomerApprovalLink, CustomerDisapprovalLink), Subject, true, test, user.Email, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer with userlogin to website
        /// </summary>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <param name="CustomerId"></param>
        public void UserInformation_SendCustomerEmail(string CustomerEmail, string CustomerName, string UserName, string Password, int CustomerId)
        {
            string Subject = "Brugerlogin til mobilhjulskift.dk";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            // Send email to customer with user on bcc
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendEmailUserInfoStandard(CustomerName, UserName, Password), Subject, true, test, user.Email, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer with renewal of subscription - invoice is attached
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="SubscriptionNumber"></param>
        /// <param name="InvoiceId"></param>
        /// <param name="attachment"></param>
        /// <param name="FileName"></param>
        public void SubscriptionRenewal_SendCustomerInvoice(int CustomerId, string CustomerEmail, string CustomerName, string SubscriptionNumber, string InvoiceId, byte[] attachment, string FileName, string PaymentAction, string PaymentLink)
        {
            string Subject = "Fornyelse af abonnement " + SubscriptionNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            MemoryStream attach = new MemoryStream();
            attach.Write(attachment, 0, attachment.Length);
            attach.Position = 0;

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["FinanceEmailAddress"].ToString(), message.SendCustomerSubscriptionRenewalOrderConfirmation(CustomerName, SubscriptionNumber, PaymentLink, CustomerId.ToString(), InvoiceId, PaymentAction), Subject, true, test, null, attach, FileName, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer with information about deactivation of subscription
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="SubscriptionNumber"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="TireSetActionText"></param>
        public void SubscriptionDeactivation_SendCustomerNotification(int CustomerId, string CustomerEmail, string CustomerName, string SubscriptionNumber, string RegistrationNumber, string TireSetActionText)
        {
            string Subject = "Deaktivering af abonnement " + SubscriptionNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendSubscriptionDeactivationCustomerNotification(CustomerName, SubscriptionNumber, RegistrationNumber, TireSetActionText), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer with information about deactivation of subscription - invoice is attached
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="SubscriptionNumber"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="TireSetActionText"></param>
        /// <param name="InvoiceId"></param>
        /// <param name="attachment"></param>
        /// <param name="FileName"></param>
        public void SubscriptionDeactivation_SendCustomerNotification(int CustomerId, string CustomerEmail, string CustomerName, string SubscriptionNumber, string RegistrationNumber, string TireSetActionText, string InvoiceId, byte[] attachment, string FileName)
        {
            string Subject = "Deaktivering af abonnement " + SubscriptionNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            MemoryStream attach = new MemoryStream();
            attach.Write(attachment, 0, attachment.Length);
            attach.Position = 0;

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendSubscriptionDeactivationCustomerNotification(CustomerName, SubscriptionNumber, RegistrationNumber, TireSetActionText), Subject, true, test, null, attach, FileName, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer with information about replacement of car with new one
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="SubscriptionNumber"></param>
        /// <param name="RegistrationNumberOld"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="TireSetActionText"></param>
        public void ReplaceCar_SendCustomerNotification(int CustomerId, string CustomerEmail, string CustomerName, string SubscriptionNumber, string RegistrationNumberOld, string RegistrationNumber, string TireSetActionText)
        {
            string Subject = "Udskiftning af bil " + SubscriptionNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendReplaceCarCustomerNotification(CustomerName, SubscriptionNumber, RegistrationNumberOld, RegistrationNumber, TireSetActionText), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer with information about replacement of car with new one - invoice attached
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="SubscriptionNumber"></param>
        /// <param name="RegistrationNumberOld"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="TireSetActionText"></param>
        /// <param name="InvoiceId"></param>
        /// <param name="attachment"></param>
        /// <param name="FileName"></param>
        public void ReplaceCar_SendCustomerNotification(int CustomerId, string CustomerEmail, string CustomerName, string SubscriptionNumber, string RegistrationNumberOld, string RegistrationNumber, string TireSetActionText, string InvoiceId, byte[] attachment, string FileName)
        {
            string Subject = "Udskiftning af bil " + SubscriptionNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            MemoryStream attach = new MemoryStream();
            attach.Write(attachment, 0, attachment.Length);
            attach.Position = 0;

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendReplaceCarCustomerNotification(CustomerName, SubscriptionNumber, RegistrationNumberOld, RegistrationNumber, TireSetActionText), Subject, true, test, null, attach, FileName, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer about creation of subscription - no invoice attached
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="SubscriptionNumber"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="TireSetActionText"></param>
        public void CreateSubscriptionAndCar_SendCustomerNotification(int CustomerId, string CustomerEmail, string CustomerName, string SubscriptionNumber, string RegistrationNumber, string TireSetActionText)
        {
            string Subject = "Oprettelse af abonnement " + SubscriptionNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendCreateSubscriptionAndCarCustomerNotification(CustomerName, SubscriptionNumber, RegistrationNumber, TireSetActionText), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to customer about creation of subscription attached with invoice
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="SubscriptionNumber"></param>
        /// <param name="RegistrationNumber"></param>
        /// <param name="TireSetActionText"></param>
        /// <param name="InvoiceId"></param>
        /// <param name="attachment"></param>
        /// <param name="FileName"></param>
        public void CreateSubscriptionAndCar_SendCustomerNotification(int CustomerId, string CustomerEmail, string CustomerName, string SubscriptionNumber, string RegistrationNumber, string TireSetActionText, string InvoiceId, byte[] attachment, string FileName)
        {
            string Subject = "Oprettelse af abonnement " + SubscriptionNumber;
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            MembershipUser user = Membership.GetUser();

            MemoryStream attach = new MemoryStream();
            attach.Write(attachment, 0, attachment.Length);
            attach.Position = 0;

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendCreateSubscriptionAndCarCustomerNotification(CustomerName, SubscriptionNumber, RegistrationNumber, TireSetActionText), Subject, true, test, null, attach, FileName, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        /// <summary>
        /// Function that sends email to internal finance email inbox with notification about invoices for handling
        /// </summary>
        /// <param name="Subject"></param>
        /// <param name="HTMLmessage"></param>
        public void SendFinanceInternalEmailNotification(string Subject, string HTMLmessage)
        {
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));
            Shared email = new Shared();

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            //MembershipUser user = Membership.GetUser();

            email.SendEmail(ConfigurationSettings.AppSettings["FinanceEmailAddress"].ToString(), ConfigurationSettings.AppSettings["EmailAddress"].ToString(), HTMLmessage, Subject, true, test, null, null, null);
        }

        /// <summary>
        /// Function that sends email to internal sales email inbox with notification about ordre handling
        /// </summary>
        /// <param name="Subject"></param>
        /// <param name="HTMLmessage"></param>
        public void SendSalesInternalEmailNotification(string Subject, string HTMLmessage)
        {
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));
            Shared email = new Shared();

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            //MembershipUser user = Membership.GetUser();

            email.SendEmail("salg@mobilhjulskift.dk", ConfigurationSettings.AppSettings["EmailAddress"].ToString(), HTMLmessage, Subject, true, test, null, null, null);
        }

        /// <summary>
        /// Function that sends email to internal finance email inbox with notification about invoices for handling
        /// </summary>
        /// <param name="Subject"></param>
        /// <param name="HTMLmessage"></param>
        /// <param name="Email"></param>
        public void SendInternalEmailNotification(string Subject, string HTMLmessage, string Email)
        {
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));
            Shared email = new Shared();

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            email.SendEmail(Email, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), HTMLmessage, Subject, true, test, null, null, null);
        }

        /// <summary>
        /// Function that sends email to customer with userlogin to website
        /// </summary>
        /// <param name="CustomerEmail"></param>
        /// <param name="CustomerName"></param>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <param name="CustomerId"></param>
        public void CustomerBookingLink_SendCustomerEmail(string CustomerEmail, string CustomerName, int CustomerId, MembershipUser user, string BookingLink)
        {
            string Subject = "Booking link til mobilhjulskift.dk";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            if (user == null)
            {
                user = Membership.GetUser();
            }

            // Send email to customer - no bcc email
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendCustomerBookingLink(CustomerName, BookingLink), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), new Guid(user.ProviderUserKey.ToString()));
        }

        public void SendTireQuotation(string CustomerEmail, int CustomerId, string CustomerName, string RegistrationNumber, string TireTypeDescription, string Note, string HF, string VF, string HB, string VB, string TireTreadRecommendedChange, string AcceptLink, string RejectLink, string TireDescription, string Quantity, string TirePriceExVat, string TirePriceTotalExVat, string MontPriceExVat, string MontPriceTotalExVat, string TotalExVat, string TotalVat, string Total, string ExpireDetails)
        {
            string Subject = "Mobilhjulskift.dk - Tilbud på udskiftning af dæk";
            bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationSettings.AppSettings["TestEnvironmentOn"]));

            EmailNotification.EmailNotification message = new EmailNotification.EmailNotification();

            Shared email = new Shared();

            Guid SystemUserId = new Guid(Membership.GetUser().ProviderUserKey.ToString()); // System ID - Jannik79

            // Send email to customer
            email.SendEmail(CustomerEmail, ConfigurationSettings.AppSettings["EmailAddress"].ToString(), message.SendTireQuotation(CustomerName, RegistrationNumber, TireTypeDescription, Note, HF, VF, HB, VB, TireTreadRecommendedChange, AcceptLink, RejectLink, TireDescription, Quantity, TirePriceExVat, TirePriceTotalExVat, MontPriceExVat, MontPriceTotalExVat, TotalExVat, TotalVat, Total, ExpireDetails), Subject, true, test, null, null, null, Convert.ToInt32(CustomerId), SystemUserId);
        }

        #endregion


        #region SMS Messages

        public void SendSMS()
        {
            // Only testing - send to test mail
            //(1) Create the MailMessage instance 
            MailMessage mm = new MailMessage(ConfigurationSettings.AppSettings["EmailAddress"].ToString(), "sms@smsgw.dk");
                
            //(2) Assign the MailMessage's properties 
            mm.Subject = "mobilhjulskift.dk:po4beey";
            mm.Body = "#25137172" + System.Environment.NewLine + "Dette er en test :-)";
            mm.IsBodyHtml = false;

            //(3) Create the SmtpClient object 
            SmtpClient smtp = new SmtpClient();
            smtp.EnableSsl = true;

            //(4) Send the MailMessage (will use the Web.config settings) 
            smtp.Send(mm);

            smtp.Dispose();
        }

        #endregion
    }
}